<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>编辑</title>
		<link rel="stylesheet" type="text/css" href="../../plugins/layui/css/layui.css" />
		<link href="../../kitAdmin/css/app.css" rel="stylesheet" type="text/css" />
		<link rel="stylesheet" type="text/css" href="../../plugins/select2/dist/css/select2.min.css" />
	</head>

	<body>
		<div class='kit-table'>
			<div style='margin:10px'>

				<form class='layui-form' action='' lay-filter='form-edit'>
					<input type='hidden' name='id' id="id" data-link='{:id}' />
					<div class='layui-form-item'>
						<label class='layui-form-label'>选择状态：</label>
						<div class="layui-input-block" style="width: 240px!important;">
							<select data-link='{:state}' id='_state' name='state' lay-filter="state" lay-verify="required">
								<option value='7'>完成</option>
								<option value='1'>无课</option>
								<option value='2'>学生请假</option>
								<option value='3'>学生缺席</option>
								<option value='4'>老师请假</option>
								<option value='5'>老师缺席</option>
								<option value='6'>补课</option>
								<option value='0'>默认</option>
							</select>
						</div>
					</div>
					<div class='layui-form-item'>
						<label class='layui-form-label'>上课教材：</label>
						<div class="layui-input-block" style="width: 240px!important;">
							<select placeholder='' data-link='{:material}' id='_material' name='material' lay-filter="material" lay-verify="required">
								<option value="">教材</option>
							</select>
						</div>
					</div>
					<div class='layui-form-item'>
						<label class='layui-form-label'>教材级别：</label>
						<div class="layui-input-block" style="width: 240px!important;">
							<select id='materialLevel' name='materialLevel' data-link='{:materialLevel}' lay-filter="materialLevel" lay-verify="required">
								<option value=""></option>
							</select>
						</div>
					</div>
					<div class="layui-form-item layui-form-text">
						<label class="layui-form-label">表现</label>
						<div class="layui-input-block">
							<textarea style="width: 45%!important;" data-link='{:performance}' id='_performance' name='performance' placeholder="请输入内容" class="layui-textarea"></textarea>
						</div>
					</div>
					<div class="layui-form-item layui-form-text">
						<label class="layui-form-label">作业</label>
						<div class="layui-input-block">
							<textarea style="width: 45%!important;" data-link='{:homework}' id='_homework' name='homework' placeholder="请输入内容" class="layui-textarea"></textarea>
						</div>
					</div>
					<div class="layui-form-item layui-form-text">
						<label class="layui-form-label">下次上课内容</label>
						<div class="layui-input-block">
							<textarea style="width: 45%!important;" data-link='{:contentNextLecture}' id='_contentNextLecture' name='contentNextLecture' placeholder="请输入内容" class="layui-textarea"></textarea>
						</div>
					</div>

				</form>
			</div>
		</div>
		<script src="../../common/js/jquery.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../static/js/base.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../plugins/jsviews/jsviews.js" type="text/javascript"></script>
		<script src="../../plugins/select2/dist/js/select2.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../plugins/laydate5.0.9/laydate.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../plugins/layui/layui.js"></script>
		<script type="text/javascript">
			var uid = getQueryVariable('id');
			jQuery(document).ready(function() {
				$('#id').val(uid);
				init();
				bindFormData();
			});
			var callback_save = function() {
				return $('.layui-form').serialize();
			}
			var init = function() {
				$.ajax({
					url:baseUrl+ '/lessons', //课程-教材
					type: 'get',
					async: false,
					success: function(data) {

						var htm = "";
						data = data.rows;
						for(var i = 0; i < data.length; i++) {
							htm += '<option value="' + data[i].id + '">' + data[i].nameEn + '</option>';
						}
						$('#_material').append(htm);
					},
					error: function() {
						parent.layer.alert('加载课程信息失败！');
					}
				});
			}

			function bindFormData() {
				if(uid) {
					$.ajax({
						url:baseUrl+ '/curriculumSchedules/' + uid,
						type: 'get',
						success: function(data) {
							data = data.data;
							$.link(true, ".kit-table", data);
							//							$('select').select2().change();
							$('#material').val(data.material);

							if(data.material.length !=0){
                                renderForm(data);
                            }
						},
						error: function() {
							parent.layer.alert('系统或网络错误！');
						}
					});
				}
			}

			layui.use(['form', 'laydate'], function() {
				var form = layui.form;
				//监听变化
				form.on('select(material)', function(data) {
					$.ajax({
						url:baseUrl+ '/lessonLevels?lessonId=' + data.value,
						type: 'get',
						async: false,
						success: function(data) {
							var htm = "";
							data = data.rows;
							for(var i = 0; i < data.length; i++) {
								htm += '<option value="' + data[i].levelId + '">' + data[i].text + '</option>';
								// htm += '<option value="' + data[i].levelId + '">年级：' + data[i].levelName + '</option>';
							}

                            $("#materialLevel").find("option:selected").text("");
                            $("#materialLevel").empty();

							$('#materialLevel').append(htm);
							form.render('select', 'materialLevel');
							form.render('select');
						},
						error: function() {
							parent.layer.alert('加载教师信息失败！');
						}
					});
				});
				//监听提交
				form.on('submit(formDemo)', function(data) {
					layer.msg(JSON.stringify(data.field));
					return false;
				});
			});

			function renderForm(data) {
				$.ajax({
					url:baseUrl+ '/lessonLevels?lessonId=' + data.material,
					type: 'get',
					async: false,
					success: function(data) {
						var htm = "";
						data = data.rows;
						for(var i = 0; i < data.length; i++) {
							// htm += '<option value="' + data[i].levelId + '">年级：' + data[i].levelName + '</option>';
							htm += '<option value="' + data[i].levelId + '">' + data[i].text + '</option>';
						}
						$('#materialLevel').append(htm);
						
					},
					error: function() {
						parent.layer.alert('加载教师信息失败！');
					}
				});
				//-------------------------------------
				$('#materialLevel').val(data.materialLevel);
				layui.use('form', function() {
					var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
					form.render();
				});
			}
		</script>
	</body>

</html>